package com.lisp.springframework.core.aop.aspectj.xml;

import org.springframework.context.support.ClassPathXmlApplicationContext;

// run with vm args "-javaagent:spring-instrument.jar" 
public class AspectJXmlApp 
{
    public static void main( String[] args ) {
        try(ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring-aspectj.xml");) {            
            
            MyServiceA myServiceA = context.getBean(MyServiceA.class);
            myServiceA.sayHello("mySerivceA from spring"); // 由于AspectJ同时对代理类和原始类生效，切面会被执行2次
            
            myServiceA.print("mySerivceA from spring");
            
            new MyServiceA().sayHello("new myServiceA"); 

            NonSpringManaged nsm = new NonSpringManaged();
            nsm.sayHello("nonSpringManaged");
            
            MyServiceB myServiceB = context.getBean(MyServiceB.class);
            myServiceB.sayHello("mySerivceB from spring");
        }
    }
}
